Skip to main content

pacenotes_installer\engine\execute/
execute_error.rs

1#[derive(Clone, Debug, PartialEq, Eq)]
2pub enum ExecuteError {
3    Io {
4        doing: String,
5        reason: String,
6    },
7    /// Usually a CRC mismatch; the package stays `installing` in the ledger,
8    /// so the next run cleans up after it.
9    Extract {
10        package: String,
11        reason: String,
12    },
13    Ledger {
14        reason: String,
15    },
16}
17
18impl ExecuteError {
19    pub(super) fn io(doing: impl Into<String>, error: impl std::fmt::Display) -> ExecuteError {
20        ExecuteError::Io {
21            doing: doing.into(),
22            reason: error.to_string(),
23        }
24    }
25
26    pub(super) fn extract(package: &str, reason: impl std::fmt::Display) -> ExecuteError {
27        ExecuteError::Extract {
28            package: package.to_string(),
29            reason: reason.to_string(),
30        }
31    }
32
33    pub(crate) fn ledger(error: std::io::Error) -> ExecuteError {
34        ExecuteError::Ledger {
35            reason: error.to_string(),
36        }
37    }
38}
39
40impl std::fmt::Display for ExecuteError {
41    fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
42        match self {
43            ExecuteError::Io { doing, reason } => write!(formatter, "{doing}: {reason}"),
44            ExecuteError::Extract { package, reason } => {
45                write!(formatter, "{package} could not be installed: {reason}")
46            }
47            ExecuteError::Ledger { reason } => write!(
48                formatter,
49                "the installation record could not be updated: {reason}"
50            ),
51        }
52    }
53}